<?php

namespace app\admin\controller;

use app\admin\model\UserLevel as UserLevelModel;


class UserLevelController extends BaseController
{
    //列表
    public function index()
    {
        $this->assign([
            'data' => UserLevelModel::order(['id'=>"asc"])->paginate(15,false,['type'=>'page\Page']),
        ]);
        return $this->fetch('user_level/index');
    }
    //添加
    public function add()
    {
        if($this->request->isPost()){
            $data = input('post.');
            $userLevel = new UserLevelModel($data);
            $userLevel->allowField(true)->isUpdate(false)->save();
            return array('status' => 1,'msg' => '添加成功','icon' => 1);
        }
        return $this->fetch('user_level/add');
    }

    //修改
    public function edi()
    {
        if($this->request->isPost()) {
            $data = input('post.');
            $userLevel = new UserLevelModel();
            $userLevel->allowField(true)->isUpdate(true)->update($data);
            return array('status' => 1,'msg' => '修改成功');
        }
        $list =  UserLevelModel::find(input('id/d'));
        $this->assign([
             'list' => $list,
        ]);
        return $this->fetch('user_level/edi');
    }
    //删除
    public function del()
    {
        UserLevelModel::destroy(input('id/d'));
        return array('status' => 1,'msg' => '删除成功','icon' => 1);
    }
}